﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace dreametryVersion2
{
    public static class message
    {
        public static String YesNo(String messageTitle, String textMessage)
        {
            String returnValue = "";
            Form message = new Form()
            {
                Width = 325,
                Height = 150,
                FormBorderStyle = FormBorderStyle.None,
                BackColor = System.Drawing.ColorTranslator.FromHtml(global.themeColor),
                Text = messageTitle,
                Font = new Font("Segoe UI", 9, FontStyle.Regular),
                ForeColor = Color.White,
                StartPosition = FormStartPosition.CenterScreen,
                Padding = new Padding(1,30,1,1),
            };

            Label title = new Label()
            {
                AutoEllipsis = true,
                Top  = 7,
                Left = 10,
                Width = 300,
                Text = messageTitle,
            };

            Panel body = new Panel()
            {
                BackColor = System.Drawing.ColorTranslator.FromHtml(global.themeColor),
                Dock = DockStyle.Fill
            };

            Label text = new Label()
            {
                AutoSize = false,
                AutoEllipsis = true,
                Dock = DockStyle.Top,
                Height = 70,
                Padding = new Padding(30, 15, 30, 0),
                Text = textMessage,
                TextAlign = ContentAlignment.MiddleLeft,
            };

            Button yes = new Button()
            {
                Top = 80,
                Left = 170,
                Width = 70,
                Height = 30,
                Text = "Yes",
                BackColor = System.Drawing.ColorTranslator.FromHtml(global.themeColor),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat,
                Cursor = Cursors.Hand
            };yes.FlatAppearance.BorderSize = 0;
            yes.Click += (sender, e) => {
                returnValue = "Yes";
                message.Close();
            };

            Button no = new Button()
            {
                Top = 80,
                Left = 245,
                Width = 70,
                Height = 30,
                Text = "No",
                BackColor = System.Drawing.ColorTranslator.FromHtml(global.themeColor),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat,
                Cursor = Cursors.Hand
            }; no.FlatAppearance.BorderSize = 0;
            no.Click += (sender, e) => {
                returnValue = "No";
                message.Close();
            };

            body.Controls.Add(no);
            body.Controls.Add(yes);
            body.Controls.Add(text);
            message.Controls.Add(title);
            message.Controls.Add(body);
            message.ShowDialog();

            return returnValue;
        }
        public static void Ok(String messageTitle, String textMessage)
        {
            Form message = new Form()
            {
                Width = 325,
                Height = 150,
                FormBorderStyle = FormBorderStyle.None,
                BackColor = System.Drawing.ColorTranslator.FromHtml(global.themeColor),
                Text = "Choose",
                Font = new Font("Segoe UI", 9, FontStyle.Regular),
                ForeColor = Color.White,
                StartPosition = FormStartPosition.CenterScreen,
                Padding = new Padding(1, 30, 1, 1),
            };

            Label title = new Label()
            {
                AutoEllipsis = true,
                Top = 7,
                Left = 10,
                Width = 300,
                Text = messageTitle,
            };

            Panel body = new Panel()
            {
                BackColor = System.Drawing.ColorTranslator.FromHtml(global.themeColor),
                Dock = DockStyle.Fill
            };

            Label text = new Label()
            {
                AutoSize = false,
                AutoEllipsis = true,
                Dock = DockStyle.Top,
                Height = 70,
                Padding = new Padding(30, 15, 30, 0),
                Text = textMessage,
                TextAlign = ContentAlignment.MiddleLeft,
            };

            Button ok = new Button()
            {
                Top = 80,
                Left = 245,
                Width = 70,
                Height = 30,
                Text = "Ok",
                BackColor = System.Drawing.ColorTranslator.FromHtml(global.themeColor),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat,
                Cursor = Cursors.Hand
            }; ok.FlatAppearance.BorderSize = 0;
            ok.Click += (sender, e) => {message.Close();};

            body.Controls.Add(ok);
            body.Controls.Add(text);
            message.Controls.Add(title);
            message.Controls.Add(body);
            message.ShowDialog();
        }
        public static void OkError(String messageTitle, String textMessage)
        {
            Form message = new Form()
            {
                Width = 325,
                Height = 150,
                FormBorderStyle = FormBorderStyle.None,
                BackColor = Color.Brown,
                Text = "Choose",
                Font = new Font("Segoe UI", 9, FontStyle.Regular),
                ForeColor = Color.White,
                StartPosition = FormStartPosition.CenterScreen,
                Padding = new Padding(1, 30, 1, 1),
            };

            Label title = new Label()
            {
                AutoEllipsis = true,
                Top = 7,
                Left = 10,
                Width = 300,
                Text = messageTitle,
            };

            Panel body = new Panel()
            {
                BackColor = Color.IndianRed,
                Dock = DockStyle.Fill
            };

            Label text = new Label()
            {
                AutoSize = false,
                AutoEllipsis = true,
                Dock = DockStyle.Top,
                Height = 70,
                Padding = new Padding(30, 15, 30, 0),
                Text = textMessage,
                TextAlign = ContentAlignment.MiddleLeft,
            };

            Button ok = new Button()
            {
                Top = 80,
                Left = 245,
                Width = 70,
                Height = 30,
                Text = "Ok",
                BackColor = Color.Brown,
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat,
                Cursor = Cursors.Hand
            }; ok.FlatAppearance.BorderSize = 0;
            ok.Click += (sender, e) => { message.Close(); };

            body.Controls.Add(ok);
            body.Controls.Add(text);
            message.Controls.Add(title);
            message.Controls.Add(body);
            message.ShowDialog();
        }
        public static void adminMessage(String textmessageadmin, String plocal, String pRemote)
        {
            Socket sck;
            EndPoint epLocal, epRemote;
          //  String sLocal, sRemote;



            sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

            try
            {
                epLocal = new IPEndPoint(IPAddress.Parse(chat.GetLocalIP()), Convert.ToInt32(plocal));
                sck.Bind(epLocal);

                epRemote = new IPEndPoint(IPAddress.Parse(chat.getAdminIP()), Convert.ToInt32(pRemote));
                sck.Connect(epRemote);

              //  byte[] buffer = new byte[1500];
              //  sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallback), buffer);

                //  button1.Text = "reConnected";

            }
            catch (Exception exp)
            {
                Console.Write(exp);
            }


            Form message = new Form()
            {
                Width = 350,
                Height = 300,
                FormBorderStyle = FormBorderStyle.None,
                BackColor = Color.Teal,
                Text = "Choose",
                Font = new Font("Segoe UI", 9, FontStyle.Regular),
                ForeColor = Color.White,
                StartPosition = FormStartPosition.CenterScreen,
                Padding = new Padding(1, 30, 1, 1),
                TopMost = true,
                //ShowInTaskbar = false
            };

            Label title = new Label()
            {
                AutoEllipsis = true,
                Top = 7,
                Left = 10,
                Width = 300,
                Text = "Message from admin",
            };

            Panel body = new Panel()
            {
                BackColor = Color.White,
                Dock = DockStyle.Fill
            };

            Panel pnlText = new Panel()
            {
                Dock = DockStyle.Top,
                BackColor = Color.White,
                Height = 100,
                Padding = new Padding(10)
            };

            RichTextBox text = new RichTextBox()
            {
                Dock = DockStyle.Fill,
                BackColor = Color.White,
                BorderStyle = BorderStyle.None,
                ForeColor = Color.DimGray,
                ReadOnly = true,
                Multiline = true,
                Height = 100,
                Text = textmessageadmin
            };

            Panel pnlReply = new Panel()
            {
                Dock = DockStyle.Fill,
                BackColor = Color.White,
                Height = 100,
                Padding = new Padding(10)
            };

            Label lblReply = new Label()
            {
                Dock = DockStyle.Top,
                Text = "your reply",
                ForeColor = Color.DimGray
            };

            TextBox reply = new TextBox()
            {
                Dock = DockStyle.Fill,
                BackColor = Color.WhiteSmoke,
                BorderStyle = BorderStyle.None,
                ForeColor = Color.DimGray,
                Multiline = true,
                Height = 100,
            };

            Panel pnlReplyButton = new Panel()
            {
                Dock = DockStyle.Bottom,
                BackColor = Color.White,
                Height = 40,
                Padding = new Padding(7,7,0,7)
            };

            Button btnReply = new Button()
            {
                Text = "reply",
                Dock = DockStyle.Right,
                BackColor = Color.Teal,
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat,
                Cursor = Cursors.Hand
            };

            pnlText.Controls.Add(text);

            pnlReplyButton.Controls.Add(btnReply);

            pnlReply.Controls.Add(reply);
            pnlReply.Controls.Add(lblReply);
            pnlReply.Controls.Add(pnlReplyButton);

            message.Controls.Add(pnlReply);
            message.Controls.Add(pnlText);
            message.Controls.Add(title);
            message.Controls.Add(body);
            
            btnReply.Click += (sender, e) => {
                try
                {
                    System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
                    byte[] msg = new byte[1500];

                    msg = enc.GetBytes(reply.Text);
                    sck.Send(msg);
          
                }
                catch (Exception exp)
                {
                    Console.Write(exp);
                }
                message.Close();
            };
            message.ShowDialog();
        }


        private static List<String> str = new List<String>();
        private static List<String> str1 = new List<String>();
        private static Panel body = new Panel();

        public static String DropFiles()
        {
            string path = @"Z:\_____Codiga\___Uploading Queue (Mug Shots for SM and ME)\TEEZILY CAMPAIGNS";
            String returnValue = "";
            Form mainbody = new Form()
            {
                Width = 400,
                Height = 300,
                FormBorderStyle = FormBorderStyle.None,
                BackColor = ColorTranslator.FromHtml(global.themeColor),
                Font = new Font("Segoe UI", 9, FontStyle.Regular),
                ForeColor = Color.White,
                StartPosition = FormStartPosition.CenterScreen,
                Padding = new Padding(1, 30, 1, 1),
            };

            Button button = new Button() {
                Text = "Browse...",
                Width = mainbody.Width,
                Dock = DockStyle.Bottom,
                BackColor = ColorTranslator.FromHtml(global.themeColor),
                FlatStyle = FlatStyle.Flat,
                Cursor = Cursors.Hand
            };button.FlatAppearance.BorderSize = 0;
           
            FolderBrowserDialog folderBrowse = new FolderBrowserDialog()
            {
                
            };


            Label label = new Label()
            {
                Text = "Drop PNG to Uploading Queue",
                Padding = new Padding(7),
                ForeColor = Color.White,
                Width = mainbody.Width,
                Height = 30
            };


            body = new Panel()
            {
                BackColor = ColorTranslator.FromHtml(global.themeColor),
                Dock = DockStyle.Fill,
                AllowDrop = true
            };
            body.DragEnter += Body_DragEnter;
            body.DragLeave += Body_DragLeave;
           
            button.Click += (sender, e) => {
                folderBrowse.Description = "Select folder Location";
                folderBrowse.SelectedPath = @"Z:\_____Codiga\___Uploading Queue (Mug Shots for SM and ME)\TEEZILY CAMPAIGNS";
                DialogResult result = folderBrowse.ShowDialog();
                if (result == DialogResult.OK)
                {
                    path = Path.GetFullPath(folderBrowse.SelectedPath);
                    string lastDirectory = path.Split(new char[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).Last();
                    label.Text = "Drop PNG to "+lastDirectory;

                }
            };

            body.DragDrop += (sender, e) => {

                for (int i = 0; i < str.Count; i++)
                {
                    //File.WriteAllBytes(@"C:\MyFile.bin", WindowsFormsApplication2.Properties.Resources.Form1);
                    String fl = Path.GetFileName(str[i].ToString());
                    String full = Path.GetFullPath(str1[i].ToString());

                    string toPath = path +@"\"+ fl;
                    //MessageBox.Show(toPath);
                    string source = full;
                    try
                    {
                        try
                        {
                            File.Copy(source, toPath);
                        }
                        catch
                        {
                            Directory.Move(source, toPath);
                        }
                    }
                    catch { }
                }
                str.Clear();
                str1.Clear();

                returnValue = "Yes";
                mainbody.Close();
            };


            mainbody.Controls.Add(label);
            mainbody.Controls.Add(body);
            mainbody.Controls.Add(button);
            mainbody.ShowDialog();

            return returnValue;
      
        }

        private static void Body_DragLeave(object sender, EventArgs e)
        {
            body.BackColor = ColorTranslator.FromHtml(global.themeColor);
        }

        private static void Body_DragDrop(object sender, DragEventArgs e)
        {
            
     
        }

        private static void Body_DragEnter(object sender, DragEventArgs e)
        {
            body.BackColor = Color.WhiteSmoke;
            e.Effect = DragDropEffects.All;
            String[] files = (String[])e.Data.GetData(DataFormats.FileDrop, false);
            for (int i = 0; i < files.Length; i++)
            {
                str.Add(Path.GetFileName(files[i].ToString()));

            }

            for (int i = 0; i < files.Length; i++)
            {
                str1.Add(files[i].ToString());

            }
        }
    }
}
